package com.yuhs.zixing.study.multithread.mashibing.t001base.t004.method;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * Function: 线程方法 001 sleep
 * sleep 就是当前线程休眠一段时间，给别的线程去执行
 * sleep 等睡眠时间到了就自动复活
 *
 * @Author yuhongsheng
 * @Date: 2023-12-18 22:25:17
 */
@Slf4j
public class ThreadMethod001Sleep {

    public static void main(String[] args) {
        testSleep();
    }

    private static void testSleep() {
        new Thread(ThreadMethod001Sleep::run).start();
    }

    @SneakyThrows
    private static void run() {
        for (int i = 0; i < 10; i++) {
            log.atInfo().log("测试睡眠 {}", i);
            TimeUnit.SECONDS.sleep(1);
        }
    }
}
